#include <iostream>
#include <string>

int const maxn = 2000002;
int next[maxn];
std::string s1, s2;

void kmp_pre(std::string s)
{
	int i = 0, j = next[0] = -1;
	while (i < (int)s.size()) {
		while (-1 != j && s[i] != s[j]) j = next[j];
		next[++i] = ++j;
	}
}

int main()
{
	int T;
	std::cin >> T;
	while (T--) {
		std::cin >> s1 >> s2;
		int len = s1.size();
		kmp_pre(s2 + s1 + '$');
//		for (int i = 0; i <= 2*len+1; i++) std::cout << next[i] << ' '; std::cout << '\n';
		std::string ans(std::max(len - next[2*len], 0), '0');
		for (int j = std::min(next[2*len], len); next[j] != -1; j = next[j]) {
			ans += '1';
			ans += std::string(j-next[j]-1, '0');
		}

		std::cout << ans << '\n';
	}
}
